<script type="text/javascript">
$(function() {
  window.md = new Markdown.Converter();

  var project = new Fulcrum.Project({"project":{"iteration_length":1,"last_changeset_id":123,"iteration_start_day":1,"point_values":[0,1,2,3,5,8],"default_velocity":10,"id":999999,"start_date":"2012/03/08"}});
  project.users.reset([{"user":{"name":"Test User","email":"test@example.com","initials":"TU","id":1}}]);
  project.current_user = new Fulcrum.User({"user":{"name":"Test User","email":"test@example.com","initials":"TU","id":1}});

  project.stories.fetch = function() {};
  window.project = project;

  var done = new Fulcrum.ColumnView({
    id: 'done', name: '<%= t('.done') %>', el: $('td.done_column'), sortable: false
  }).render();
  $('#column-toggles').append(
    new Fulcrum.ColumnVisibiltyButtonView({columnView: done}).render().el
  );

  var in_progress = new Fulcrum.ColumnView({
    id: 'in_progress', name: '<%= t('.in_progress') %>', el: $('td.in_progress_column'),
    sortable: true
  }).render();
  $('#column-toggles').append(
    new Fulcrum.ColumnVisibiltyButtonView({columnView: in_progress}).render().el
  );

  var backlog = new Fulcrum.ColumnView({
    id: 'backlog', name: '<%= t('.backlog') %>', el: $('td.backlog_column'), sortable: true
  }).render();
  $('#column-toggles').append(
    new Fulcrum.ColumnVisibiltyButtonView({columnView: backlog}).render().el
  );

  var chilly_bin = new Fulcrum.ColumnView({
    id: 'chilly_bin', name: '<%= t('.icebox') %>', el: $('td.chilly_bin_column'),
    sortable: true
  }).render();
  $('#column-toggles').append(
    new Fulcrum.ColumnVisibiltyButtonView({columnView: chilly_bin}).render().el
  );


  var view;
  appendStoryTo(chilly_bin, {"title":"Unestimated feature"});
  appendStoryTo(chilly_bin, {"title":"Estimated feature","estimate":3});
  appendStoryTo(chilly_bin, {"title":"Example chore","story_type":"chore"});
  appendStoryTo(chilly_bin, {"title":"Example bug","story_type":"bug"});
  appendStoryTo(chilly_bin, {"title":"Example release","story_type":"release"});

  view = appendStoryTo(chilly_bin, {"title":"Save in progress","estimate":3});
  view.saveInProgress = true;
  view.render();
  view.disableForm();

  appendStoryTo(chilly_bin, {"title":"Editing feature","editing":true});
  appendStoryTo(chilly_bin, {
    "title":"Editing chore","story_type":"chore","editing":true
  });
  appendStoryTo(chilly_bin, {
    "title":"Editing bug","story_type":"bug","editing":true
  });
  appendStoryTo(chilly_bin, {
    "title":"Editing release","story_type":"release","editing":true
  });

  appendStoryTo(backlog, {"title":"Unestimated feature"});
  appendStoryTo(backlog, {"title":"Estimated feature","estimate":3});
  appendStoryTo(backlog, {"title":"Example chore","story_type":"chore"});
  appendStoryTo(backlog, {"title":"Example bug","story_type":"bug"});
  appendStoryTo(backlog, {"title":"Example release","story_type":"release"});
  appendStoryTo(backlog, {"title":"Estimated feature","estimate":3});
  view = appendStoryTo(backlog, {
    "title":"Save in progress","story_type":"release","editing":true
  });
  view.saveInProgress = true;
  view.render();
  view.disableForm();

  appendStoryTo(in_progress, {
    "title":"Started feature","state":"started","estimate":1
  });
  appendStoryTo(in_progress, {
    "title":"Finished feature","state":"finished", "estimate":2
  });
  appendStoryTo(in_progress, {
    "title":"Delivered feature","estimate":5, "state":"delivered"
  });
  appendStoryTo(in_progress, {
    "title":"Rejected feature","estimate":8, "state": "rejected"
  });
  appendStoryTo(in_progress, {"title":"Example chore","story_type":"chore"});
  appendStoryTo(in_progress, {"title":"Example bug","story_type":"bug"});
  appendStoryTo(in_progress, {"title":"Example release","story_type":"release"});

  appendIterationTo(done, new Fulcrum.Iteration({'number':1, stories:[]}));

  function appendStoryTo(columnView, storyAttributes, view) {

    // Increment the ID on each invocation
    if (typeof appendStoryTo.id == 'undefined') {
      appendStoryTo.id = 1;
    }
    storyAttributes.id = appendStoryTo.id++;

    var story = new Fulcrum.Story(storyAttributes);
    //story.collection = window.project.stories;
    window.project.stories.add(story);
    if (typeof view == 'undefined') {
      view = new Fulcrum.StoryView({model: story});
    }
    view.render();
    columnView.appendView(view);
    return view;
  }

  function appendIterationTo(columnView, iteration, view) {
    iteration.project = window.project;
    if (typeof view == 'undefined') {
      view = new Fulcrum.IterationView({model: iteration});
    }
    view.render();
    columnView.appendView(view);
    return view;
  }

  window.projectView = new Fulcrum.ProjectView({model: project});
  window.projectView.velocityView = new Fulcrum.ProjectVelocityView({
    model: project, el: $('#velocity')
  }).render();
  window.projectView.scaleToViewport();
  $(window).resize(projectView.scaleToViewport);

  window.projectView.notice({
    'title': 'Test card',
    'text': 'This is a testcard to expose the full UI on one page'
  });
});
</script>

<% content_for :title_bar do %>
  <div id="velocity" class="velocity"></div>
  <%= render :partial => 'projects/nav',
             :locals => {:project => @project, :show_column_toggles => true} %>
             | <a id="add_story" href="#"><%= t('add story') %></a>
<% end %>

<table class="stories" width="100%">
  <tbody>
    <tr>
      <td class="done_column" style="width: 25%"></td>
      <td class="in_progress_column" style="width: 25%"></td>
      <td class="backlog_column" style="width: 25%"></td>
      <td class="chilly_bin_column" style="width: 25%"></td>
    </tr>
  </tbody>
</table>
